package com.tjetc.service.impl;

import com.tjetc.dao.AnimalMapper;
import com.tjetc.domain.Admin;
import com.tjetc.domain.Animal;
import com.tjetc.service.AnimalService;
import com.tjetc.utils.Db;
import com.tjetc.vo.Result;

public class AnimalServiceImpl implements AnimalService {
    private AnimalMapper animalMapper= Db.getMapper(AnimalMapper.class);
    @Override
    public Result list() {
        return new Result(200,null,animalMapper.list(null));
    }

    @Override
    public Result add(Animal animal) {
        int rows=animalMapper.add(animal);
        if (rows==1){
            return new Result(200,"添加成功",null);
        }else {
            return new Result(500,"添加失败",null);
        }
    }

    @Override
    public Result update(Animal animal) {
        Animal animal1=animalMapper.getById(animal.getId());
        if (animal1!=null){
            int rows=animalMapper.update(animal);
            if (rows==1){
                return new Result(200,"修改成功",null);
            }else {
                return new Result(500,"修改失败",null);
            }
        }else {
            return new Result(500,"没有宠物",null);

        }
    }

    @Override
    public Result listByStatus(int status) {
        return new Result(200,null,animalMapper.list(0));
    }

}
